package lanou3g.myfirstapp36kr.activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import lanou3g.myfirstapp36kr.R;
import lanou3g.myfirstapp36kr.base.BaseActivity;
/**
 * Created by dllo on 16/8/19.
 */
public class ShareActivity extends BaseActivity implements OnClickListener {
    private TextView textViewSmall;
    private TextView textViewMiddle;
    private TextView textViewBig;
    private TextView textViewSuperBig;
    public static final String ACTION_CHANGE_SMALL = "lanou3g.myfirstapp36kr.activity.ACTION_CHANGE_SMALL";
    public static final String ACTION_CHANGE_MIDDLE = "lanou3g.myfirstapp36kr.activity.ACTION_CHANGE_MIDDLE";
    public static final String ACTION_CHANGE_BIG = "lanou3g.myfirstapp36kr.activity.ACTION_CHANGE_BIG";
    public static final String ACTION_CHANGE_SUPER = "lanou3g.myfirstapp36kr.activity.ACTION_CHANGE_SUPER";
    private Intent broadcast;
    private SeekBar seekBar;
    @Override
    protected int getLayout() {
        return R.layout.activity_share;
    }

    @Override
    protected void initView() {
        textViewSmall = (TextView) findViewById(R.id.tv_small);
        textViewMiddle = (TextView) findViewById(R.id.tv_middle);
        textViewBig = (TextView) findViewById(R.id.tv_big);
        textViewSuperBig = (TextView) findViewById(R.id.tv_verybig);
        broadcast = new Intent();
        seekBar = (SeekBar) findViewById(R.id.sb_light);

    }

    @Override
    protected void initData() {
        textViewSmall.setOnClickListener(this);
        textViewMiddle.setOnClickListener(this);
        textViewBig.setOnClickListener(this);
        textViewSuperBig.setOnClickListener(this);
        seekBar.setMax(100);
        seekBar.setOnSeekBarChangeListener(new SeekBarChangeListenerImp());

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_small:
                broadcast.setAction(ACTION_CHANGE_SMALL);
                sendBroadcast(broadcast);
                break;
            case R.id.tv_middle:
                broadcast.setAction(ACTION_CHANGE_MIDDLE);
                sendBroadcast(broadcast);
                break;
            case R.id.tv_big:
                broadcast.setAction(ACTION_CHANGE_BIG);
                sendBroadcast(broadcast);
                break;
            case R.id.tv_verybig:
                broadcast.setAction(ACTION_CHANGE_SUPER);
                sendBroadcast(broadcast);
                break;
        }

    }
    private void setScreenBrightness(float num){
        WindowManager.LayoutParams layoutParams = super.getWindow().getAttributes();
        layoutParams.screenBrightness = num;
        super.getWindow().setAttributes(layoutParams);
    }
    public class SeekBarChangeListenerImp implements OnSeekBarChangeListener{

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            int cur = seekBar.getProgress();
            Log.d("SeekBarChangeListenerIm", "cur:" + cur);
            ShareActivity.this.setScreenBrightness(cur * 1.0f / 100);
            //Toast.makeText(ShareActivity.this, "当前屏幕亮度" + cur * 1.0f / 100, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    }
}
